{% extends "base.html" %}

{% block title %}用户管理 - 告警系统{% endblock %}

{% block content %}
    <div class="container py-5">
        <div class="user-form">
            <div class="form-header">
                <h2><i class="bi bi-pencil-square me-2"></i>编辑用户信息</h2>
                <p class="text-muted">更新用户详细信息</p>
            </div>
            
            {% if error %}
            <div class="alert alert-danger alert-dismissible fade show mb-4" role="alert">
                <i class="bi bi-exclamation-circle me-2"></i> {{ error }}
                <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
            </div>
            {% endif %}
            
            <div class="avatar-section">
                <div class="avatar">
                    {{ user.RealName|first|upper if user.RealName else user.UserName|first|upper }}
                </div>
                <h4>{{ user.RealName or user.UserName }}</h4>
                <p class="text-muted">用户ID: {{ user.UserId }}</p>
            </div>
            
            <form action="/update_user/{{ user.UserId }}" method="post">
                <div class="mb-3">
                    <label for="UserName" class="form-label">用户名</label>
                    <input type="text" class="form-control" id="UserName" name="UserName" 
                           value="{{ user.UserName }}" required maxlength="10">
                </div>
                
                <div class="mb-3">
                    <label for="RealName" class="form-label">真实姓名</label>
                    <input type="text" class="form-control" id="RealName" name="RealName" 
                           value="{{ user.RealName or '' }}">
                </div>
                
                <div class="mb-3">
                    <label for="Contact" class="form-label">联系方式</label>
                    <input type="text" class="form-control" id="Contact" name="Contact" 
                           value="{{ user.Contact or '' }}" maxlength="15">
                </div>
                
                <div class="mb-3">
                    <label for="Role" class="form-label">用户角色</label>
                    <select class="form-select" id="Role" name="Role" required>
                        <option value="user" {% if user.Role == "user" %}selected{% endif %}>普通用户</option>
                        <option value="admin" {% if user.Role == "admin" %}selected{% endif %}>管理员</option>
                        <option value="deployer" {% if user.Role == "deployer" %}selected{% endif %}>部署人员</option>
                    </select>
                </div>
                
                <div class="mb-4">
                    <label for="NewPassword" class="form-label">新密码</label>
                    <input type="password" class="form-control" id="NewPassword" name="NewPassword">
                    <div class="form-text">留空表示不修改密码，密码长度至少为6位</div>
                </div>
                
                <div class="d-grid gap-2 d-md-flex justify-content-md-end">
                    <a href="/adminmanage" class="btn btn-outline-secondary me-md-2">
                        <i class="bi bi-arrow-left me-1"></i> 返回
                    </a>
                    <button type="submit" class="btn btn-primary">
                        <i class="bi bi-save me-1"></i> 保存更改
                    </button>
                </div>
            </form>
        </div>
    </div>
    
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
{% endblock %}